<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <FilterTables
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      selectionType="single"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTables>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" :disabled="isDisabled" type="primary">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { dealerAttach } from '@/api/omFinanceP/MoneyManage/BankInfoMaintain';
import { getRegion} from '@/api/cms-common/dealerdata/index';
import { dealerCommon } from '@/api/cms-api/origin/commonDealerType'; //经销商类型工具类

export default {
  mixins: [dictionary,dealerCommon],

  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: dealerAttach,
    fetchParams: {},
      tableList: [],
      deptDictList: [],
      isDisabled: true
    };
  },
  created() {
    // this.getDeptData();
      //初始化事业部下拉数据
    this.getDeptList();
     
  },
  methods: {
    async getDeptList(){
      let res=await getRegion({orgType:15061005})
      let arr=res.data.map(x=>({text:x.orgName,value:x.orgId}))
      this.topFilterList.find(x=>x.fieldName=='deptId').itemList=arr;
    },
    // //加载事业部数据
    // async getDeptData() {
    //   const res = await getRegion();
    //   if (res.resultCode === 200) {
    //     this.deptDictList = res.data.map(x => ({ codeId: x.id, codeCnDesc: x.orgName }));
    //     res.data.map(x => {
    //       this.columns.find(item => item.dataIndex == 'deptId').filterItems.push({ text: x.orgName, value: x.id });
    //     });
    //   }
    // },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectChangeHandle(rows) {
      if (rows.length > 0) {
        this.isDisabled = false;
        this.tableList = JSON.parse(JSON.stringify(rows));
        return;
      }
      this.isDisabled = true;
    },

    closeDrawer(type) {
      if (type == 1) {
        return this.$emit('close', false);
      }
      if (type == 2) {
        return this.$emit('close', false, this.tableList);
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入'
        }
      //   {
      //     type: 'INPUT',
      //     label: '经销商简称',
      //     fieldName: 'dealerShortName',
      //     initialValue: '',
        
      //   },
      // { 
      //         type: 'SELECT',  
      //         label: '渠道类型',  
      //         fieldName: 'dealerType',  
      //         placeholder: '请选择', 
            
      //          itemList:this.getOriginInfoDealerType(),
      //       },
      //     {
      //     type: 'SELECT',
      //     label: '事业部',
      //     fieldName: 'deptId',
      //     placeholder: '请选择',
      //     itemList:[]
      //   },
      //     {
      //       type: 'SELECT',
      //       label: '启用标记',
      //       fieldName: 'status',
      //       placeholder: '请选择',
      //        initialValue: 10031001,
      //       itemList: this.createDictList('1003'),
      //       }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '公司全称',
        //   dataIndex: 'companyName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商展厅地址',
          dataIndex: 'showRoomAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
        // {
        //   title: '经销商类型',
        //   dataIndex: 'dealerType',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('2538'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.dealerType, '2538')}</span>;
        //   }
        // },
        // {
        //   title: '经销商级别',
        //   dataIndex: 'shopLevel',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('2540'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.shopLevel, '2540')}</span>;
        //   }
        // },
        // {
        //   title: '事业部',
        //   dataIndex: 'deptId',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: [],
        //   render: props => {
        //     return <span>{this.transDictText(props.row.deptId, this.deptDictList)}</span>;
        //   }
        // },
        // {
        //   title: '事业部',
        //   dataIndex: 'deptName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '县区',
        //   dataIndex: 'districtName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // }
      ];
    }
  }
};
</script>
